package cn.guxinhu.billsystem.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * @author Guxinhu
 * @create 2021-06-21 18:17
 */
public class TimeTools {

    // 获取当前时间的工具类
    public static String getNowTime() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        return simpleDateFormat.format(date);
    }

    // 时间转时间对象的工具类
    public static Date setData(String time) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        date = simpleDateFormat.parse(time);
        return date;
    }

    // 时间转时间对象的工具类的重载
    public static Calendar setCalendar() throws ParseException {
        String dateStr = getNowTime();
        Calendar calendar = setCalendar(dateStr);
        return calendar;
    }

    // date转GregorianCalendar的工具类
    public static Calendar setCalendar(String time) throws ParseException {
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(setData(time));
        return calendar;
    }


}
